﻿//  Copyright (c) 2009 Ray Liang (http://www.dotnetage.com)
//  Dual licensed under the MIT and GPL licenses:
//  http://www.opensource.org/licenses/mit-license.php
//  http://www.gnu.org/licenses/gpl.html

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
//using DNA.Mvc.DynamicUI;

namespace DNA.Mvc.Controllers
{
    // [Log]
    //[MasterLayout]
    [HandleError(View = "Error")]
    public class HomeController : Controller
    {
        private WebSiteContext _context;
        public HomeController(WebSiteContext context) { _context = context; }

        [SiteMapAction]
        //[OutputCache(Duration = 60, VaryByParam = "*")]
        public ActionResult Index()
        {
            var web = _context.Web;
            if (!string.IsNullOrEmpty(web.DefaultUrl))
            {
                string _url = web.DefaultUrl.ToLower();
                if ((!_url.Equals("~/home/index")) && (!_url.Equals("~/home")) &&
                    (!_url.Equals("~/home/")) && (!_url.Equals("~/")) &&
                    (!_url.Equals("~/default.aspx")))
                {
                    if (Url != null)
                        return Redirect(Url.Content(_url));
                    else
                        return Redirect(_url); // This line only run in tester
                }
            }

            return View();
        }

        public ActionResult NotFound()
        {
            return View();
        }
    }
}
